//
//  HomeViewController.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/3.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "HomeViewController.h"

#import "SearchViewController.h"
#import "MessageViewController.h"

#import "FPLoginViewController.h"
#import "WebViewController.h"
#import "PaperBoardOrderViewController.h"
#import "AutobiographyViewController.h"

#import "MoreProductViewController.h"
#import "PaperBoxOrderViewController.h"
#import "PackagingExcipientViewController.h"
#import "OrderViewController.h"
#import "SolutionViewController.h"
#import "PackingDesignViewController.h"
#import "SelectBoxModelController.h"
#import "OrderPaperBoardViewController.h"
#import "ApplySceneViewController.h"
//view
#import "ModuleSelectView.h"
#import "KDCycleBannerView.h"//轮播图
#import "HomeClassTableViewCell.h"
#import "CHCardItemModel.h"
#import "HotBoxView.h"
#import "HotBoardTableViewCell.h"
#import <CoreLocation/CoreLocation.h>

@interface HomeViewController ()<CLLocationManagerDelegate, UITableViewDelegate, UITableViewDataSource, KDCycleBannerViewDataSource, KDCycleBannerViewDelegate>{
    CLLocationManager *_locationManager;//定位服务管理类
    CLGeocoder * _geocoder;//初始化地理编码器
}

@property (nonatomic, strong) BaseTableView     * tableView;

@property (nonatomic, strong) KDCycleBannerView * cycleBannerViewBottom;//轮播图
@property (nonatomic, strong) UIScrollView      * scrollView;
@property (nonatomic, strong) ModuleSelectView  * moduleView;

@property (nonatomic, strong) NSArray        * cycleBannerArray;
@property (nonatomic, strong) NSMutableArray * recommendProductArray;
@property (nonatomic, strong) NSMutableArray * hotBoxArray;
@property (nonatomic, strong) NSMutableArray * hotBoardArray;
@property (nonatomic,strong)  NSArray        * packageArray;

@end

@implementation HomeViewController

- (NSArray *)packageArray
{
    if (_packageArray == nil) {
        _packageArray = [[NSArray alloc] init];
    }
    return _packageArray;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    
    [self getBanner];
    if (kNSUDefaultReadKey(@"FactoryId")) {
        [self getProduct];
        [self getHotBox];
        [self getHoxBoard];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self initializeLocationService];
    [self setNavBar];
    [self setUI];
    
}

- (void)initData {
    self.cycleBannerArray = [NSArray array];
    self.recommendProductArray = [NSMutableArray array];
    self.hotBoxArray = [NSMutableArray array];
    self.hotBoardArray = [NSMutableArray array];
}

#pragma mark - Location
- (void)initializeLocationService {
    // 初始化定位管理器
    _locationManager = [[CLLocationManager alloc] init];
    [_locationManager requestWhenInUseAuthorization];
    
    _locationManager.delegate = self;
    // 设置定位精确度到米
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    // 设置过滤器为无
    _locationManager.distanceFilter = kCLDistanceFilterNone;
    // 开始定位
    [_locationManager startUpdatingLocation];//开始定位之后会不断的执行代理方法更新位置会比较费电所以建议获取完位置即时关闭更新位置服务
    //初始化地理编码器
    _geocoder = [[CLGeocoder alloc] init];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    
    NSLog(@"%lu",(unsigned long)locations.count);
    CLLocation * location = locations.lastObject;
    NSLog(@"%@",[NSString stringWithFormat:@"%lf", location.coordinate.longitude]);
    NSString *longitude = [NSString stringWithFormat:@"%lf",location.coordinate.longitude];
    NSString *latitude = [NSString stringWithFormat:@"%lf",location.coordinate.latitude];

    kNSUDefaultSaveVauleAndKey(longitude, @"longitude");
    kNSUDefaultSaveVauleAndKey(latitude, @"latitude");
    
    [_geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        if (placemarks.count > 0) {
            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            NSLog(@"%@",placemark.name);
            //获取城市
            NSString *city = placemark.locality;
            if (!city) {
                city = placemark.administrativeArea;
            }
            
            UIButton *locationBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, ScreenX375(66), 44)];
            [locationBtn setImage:[UIImage imageNamed:@"定位"] forState:UIControlStateNormal];
            [locationBtn setTitle:city forState:UIControlStateNormal];
            [locationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            locationBtn.titleLabel.font = Kfont(14);
            locationBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
            self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:locationBtn];
            
        }else if (error == nil && [placemarks count] == 0) {
            NSLog(@"No results were returned.");
        } else if (error != nil){
            NSLog(@"An error occurred = %@", error);
        }
    }];
    [manager stopUpdatingLocation];//不用的时候关闭更新位置服务
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    kNSUDefaultSaveVauleAndKey(@"120.038016", @"longitude");
    kNSUDefaultSaveVauleAndKey(@"30.250560", @"latitude");
}

- (void)setNavBar {
    [self setRightButton:[UIImage imageNamed:@"消息"] title:nil target:self action:@selector(turnToMessage)];
    
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 52, 30)];
    UIImageView *leftImg = [[UIImageView alloc] initWithFrame:CGRectMake(20, 4, 22, 22)];
    leftImg.image = [UIImage imageNamed:@"搜索"];
    [leftView addSubview:leftImg];
    
    UITextField *searchField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, ScreenX375(227), 30)];
    searchField.placeholder = @"搜索您需要的包装设计";
    searchField.layer.cornerRadius = ScreenX375(15);
    searchField.clipsToBounds = YES;
    searchField.backgroundColor = [UIColor whiteColor];
    searchField.leftViewMode = UITextFieldViewModeAlways;
    searchField.leftView = leftView;
    searchField.font = Kfont(13);
    self.navigationItem.titleView = searchField;
    UIButton *searchButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, ScreenX375(227), 30)];
    searchButton.backgroundColor = [UIColor clearColor];
    [searchButton addTarget:self action:@selector(turnToSearch) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationItem.titleView addSubview:searchButton];
}

- (void)selectProduct:(UIButton *)button {
    CHCardItemModel *model = self.recommendProductArray[button.tag - 100];
    if ([model.goods_type integerValue] == 2) {
        OrderPaperBoardViewController *vc = [[OrderPaperBoardViewController alloc] init];
        vc.productId = model.cardId;
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        SelectBoxModelController *vc = [[SelectBoxModelController alloc] init];
        vc.producId = model.cardId;
        vc.isPaperBox = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)turnToSearch {
    SearchViewController *vc = [[SearchViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)turnToMessage {
    MessageViewController *vc = [[MessageViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)setUI {
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - TAB_BAR_HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    if (!kNSUDefaultReadKey(@"Factory")) {
        self.moduleView = [[ModuleSelectView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        self.moduleView.isSelectFactory = YES;
        __weak __typeof(self) weakSelf = self;
        self.moduleView.selectClick = ^{
            [weakSelf.moduleView removeFromSuperview];
            [weakSelf getProduct];
            [weakSelf getHotBox];
            [weakSelf getHoxBoard];
        };
        [kKeyWindow addSubview:self.moduleView];
        [self getFactorys];
    }
}

//Net
- (void)getFactorys {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/factorys",REQUESTHEADER] andParameter:nil success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            [self.moduleView modelArrayForView:successResponse[@"data"]];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getBanner {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/banner_info",REQUESTHEADER] andParameter:nil success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            self.cycleBannerArray = successResponse[@"data"];
            [self.cycleBannerViewBottom reloadDataWithCompleteBlock:nil];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getProduct {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/recommend_product",REQUESTHEADER] andParameter:@{@"factory_id":kNSUDefaultReadKey(@"FactoryId")} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            [self.recommendProductArray removeAllObjects];
            NSArray *arr = [[successResponse[@"data"] reverseObjectEnumerator] allObjects];
            for (NSDictionary *dict in arr) {
                CHCardItemModel *model = [[CHCardItemModel alloc] initWithDic:dict];
                [self.recommendProductArray addObject:model];
            }
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 1)] withRowAnimation:UITableViewRowAnimationNone];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getHotBox {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/hot_carton",REQUESTHEADER] andParameter:@{@"factory_id":kNSUDefaultReadKey(@"FactoryId")} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError* error;
            [self.hotBoxArray removeAllObjects];
            for (NSDictionary *dict in successResponse[@"data"]) {
                HotBoxModel *model = [[HotBoxModel alloc] initWithDictionary:dict error:&error];
                model.boxId = dict[@"id"];
                [self.hotBoxArray addObject:model];
            }
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 1)] withRowAnimation:UITableViewRowAnimationNone];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getHoxBoard {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/hot_cardboard",REQUESTHEADER] andParameter:@{@"factory_id":kNSUDefaultReadKey(@"FactoryId")} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError* error;
            [self.hotBoardArray removeAllObjects];
            for (NSDictionary *dict in successResponse[@"data"]) {
                HotBoardModel *model = [[HotBoardModel alloc] initWithDictionary:dict error:&error];
                model.boardId = dict[@"id"];
                [self.hotBoardArray addObject:model];
            }
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(3, 1)] withRowAnimation:UITableViewRowAnimationNone];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 2;
    }else if (section == 3) {
        return _hotBoardArray.count;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            static NSString *cellId = @"bannerCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                self.cycleBannerViewBottom = [KDCycleBannerView new];
                self.cycleBannerViewBottom.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(190)); //位置及宽高
                self.cycleBannerViewBottom.datasource = self;
                self.cycleBannerViewBottom.delegate = self;
                self.cycleBannerViewBottom.continuous = YES; //是否连续显示
                self.cycleBannerViewBottom.autoPlayTimeInterval = 4; //时间间隔
                [cell addSubview:self.cycleBannerViewBottom];
            }
            return cell;
        }else {
            HomeClassTableViewCell *cell = [HomeClassTableViewCell cellWithTableView:tableView andIndexPath:indexPath];
            cell.indexClick = ^(NSInteger index) {
                if (index == 0) {
                    PaperBoardOrderViewController *vc = [[PaperBoardOrderViewController alloc] init];
                    [self.navigationController pushViewController:vc animated:YES];
                }else if (index == 1) {
//                    AutobiographyViewController *vc = [[AutobiographyViewController alloc] init];
                    ApplySceneViewController *vc = [[ApplySceneViewController alloc] init];
                    [self.navigationController pushViewController:vc animated:YES];
                }else if (index == 2){
                    SolutionViewController *vc = [[SolutionViewController alloc] init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
                else if (index == 3) {
                    PaperBoxOrderViewController *vc = [[PaperBoxOrderViewController alloc] init];
                    [self.navigationController pushViewController:vc animated:YES];
                }else if (index == 4) {
                    PackagingExcipientViewController *vc = [[PackagingExcipientViewController alloc] init];
                    [self.navigationController pushViewController:vc animated:YES];
                }else if (index == 5) {
                    OrderViewController *vc = [[OrderViewController alloc] init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
            };
            return cell;
        }
    }else if (indexPath.section == 3) {
        HotBoardTableViewCell *cell = [HotBoardTableViewCell cellWithTableView:tableView andIndexPath:indexPath];
        [cell initWithModel:_hotBoardArray[indexPath.row]];
        return cell;
    }else if (indexPath.section == 2) {
        static NSString *cellId = @"hotBoxCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(147))];
            _scrollView.showsVerticalScrollIndicator = false;
            _scrollView.showsHorizontalScrollIndicator = false;
            _scrollView.delegate = self;
            [cell addSubview:_scrollView];
        }
        for (UIView *subView in _scrollView.subviews) {
            [subView removeFromSuperview];
        }
        _scrollView.contentSize = CGSizeMake(ScreenX375(12) + _hotBoxArray.count * ScreenX375(136), 0);
        for (int i = 0; i < _hotBoxArray.count; i++) {
            HotBoxView *view = [[HotBoxView alloc] initWithFrame:CGRectMake(ScreenX375(12) + i * ScreenX375(136), 0, ScreenX375(125), ScreenX375(147))];
            [view initWithModel:_hotBoxArray[i]];
            view.selectClick = ^{
                HotBoxModel *model = self.hotBoxArray[i];
                SelectBoxModelController *vc = [[SelectBoxModelController alloc] init];
                vc.producId = model.boxId;
                vc.isPaperBox = YES;
                [self.navigationController pushViewController:vc animated:YES];
            };
            [_scrollView addSubview:view];
        }
        return cell;
    }else if (indexPath.section == 1) {
        static NSString *cellId = @"productCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        for (UIView *subView in cell.subviews) {
            [subView removeAllSubviews];
        }
        UIScrollView *bigScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(165))];
        bigScrollView.backgroundColor = [UIColor whiteColor];
        bigScrollView.contentSize = CGSizeMake(self.recommendProductArray.count * SCREEN_WIDTH, 0);
        bigScrollView.bounces = YES;
        bigScrollView.showsHorizontalScrollIndicator = NO;
        bigScrollView.showsVerticalScrollIndicator = NO;
        bigScrollView.delegate = self;
        bigScrollView.pagingEnabled = YES;
        [cell addSubview:bigScrollView];
        
        for (int i = 0; i < self.recommendProductArray.count; i++) {
            CHCardItemModel *model = self.recommendProductArray[i];
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13) + i * SCREEN_WIDTH, 0, SCREEN_WIDTH - ScreenX375(26), ScreenX375(165))];
            [imageView sd_setImageWithURL:[NSURL URLWithString:model.index_pic] placeholderImage:nil options:SDWebImageRetryFailed];
            imageView.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
            [bigScrollView addSubview:imageView];
            
            UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(24) + i * SCREEN_WIDTH, ScreenX375(140), ScreenX375(240), ScreenX375(20))];
            nameLabel.textColor = [UIColor whiteColor];
            nameLabel.font = Kfont(14);
            nameLabel.text = model.card_name;
            [bigScrollView addSubview:nameLabel];
            
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i * SCREEN_WIDTH, 0, SCREEN_WIDTH, ScreenX375(165))];
            [button addTarget:self action:@selector(selectProduct:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = 100 + i;
            [bigScrollView addSubview:button];
        }
        
        return cell;
    }
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 3) {
        HotBoardModel *model = _hotBoardArray[indexPath.row];
        OrderPaperBoardViewController *vc = [[OrderPaperBoardViewController alloc] init];
        vc.productId = model.boardId;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return ScreenX375(190);
        }
        return ScreenX375(159);
    }else if (indexPath.section == 1) {
        return ScreenX375(180);
    }else if (indexPath.section == 2) {
        return ScreenX375(160);
    }
    return ScreenX375(100);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section != 0) {
        return ScreenX375(53);
    }
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return ScreenX375(10);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section != 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(53))];
        view.backgroundColor = [UIColor whiteColor];
        
        UIView *rline = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenX375(15), ScreenX375(3), ScreenX375(23))];
        rline.backgroundColor = ThemeColor;
        [view addSubview:rline];
        
        UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(200), ScreenX375(24))];
        noteLabel.text = section == 1 ? @"推荐产品" : (section == 2 ? @"热门纸箱" : @"热门纸板");
        noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
        noteLabel.font = Kfont(18);
        [view addSubview:noteLabel];
        UIButton *moreBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(60), 0, ScreenX375(60), ScreenX375(53))];
        [moreBtn setTitle:@"更多 >" forState:UIControlStateNormal];
        [moreBtn setTitleColor:REXADECIMALCOLOR(@"#666666") forState:UIControlStateNormal];
        moreBtn.tag = 1000 + section;
        moreBtn.titleLabel.font = Kfont(15);
        [moreBtn addTarget:self action:@selector(turnToMore:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:moreBtn];
        
        return view;
    }
    return nil;
}

- (void)turnToMore:(UIButton *)button {
    if (button.tag == 1001) {
        MoreProductViewController *vc = [[MoreProductViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (button.tag == 1002) {
        PaperBoxOrderViewController *vc = [[PaperBoxOrderViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (button.tag == 1003) {
        PaperBoardOrderViewController *vc = [[PaperBoardOrderViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(10))];
    view.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
    return view;
}

#pragma mark 轮播图代理委托

- (NSArray *)numberOfKDCycleBannerView:(KDCycleBannerView *)bannerView{
    NSMutableArray *urlArray = [NSMutableArray array];
    for (int i = 0; i < _cycleBannerArray.count; i++) {
        NSString *url = [NSString stringWithFormat:@"%@",_cycleBannerArray[i][@"pic"]];
        [urlArray addObject:url];
    }
    return urlArray;
}

- (UIViewContentMode)contentModeForImageIndex:(NSUInteger)index{
    return UIViewContentModeScaleToFill;
}

- (void)cycleBannerView:(KDCycleBannerView *)bannerView didSelectedAtIndex:(NSUInteger)index{
    NSLog(@"点击了第%ld个",(long)index);
    if ([_cycleBannerArray[index][@"url"] length] > 0) {
        WebViewController *vc = [[WebViewController alloc] init];
        vc.url = _cycleBannerArray[index][@"url"];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
